package com.neusoft.SPNursingHome.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neusoft.SPNursingHome.po.ClientMealInfo;
import com.neusoft.SPNursingHome.po.MealCalendarWithFood;
import com.neusoft.SPNursingHome.po.MealRecord;
import com.neusoft.SPNursingHome.po.ResponseBean;
import com.neusoft.SPNursingHome.service.MealRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mealRecord")
public class MealRecordController {

    @Autowired
    private MealRecordService service;

    @GetMapping("/list")
    public ResponseBean<List<MealRecord>> listAll() {
        return service.listAll();
    }

    @GetMapping("/{id}")
    public ResponseBean<MealRecord> getById(@PathVariable Integer id) {
        return service.getById(id);
    }

    @GetMapping("/byClient")
    public ResponseBean<IPage<ClientMealInfo>> getByClient(
            @RequestParam(defaultValue = "1")  long page,
            @RequestParam(defaultValue = "10") long size,
            @RequestParam                       Integer clientId,
            @RequestParam(required = false) String startDay,
            @RequestParam(required = false) String endDay,
            @RequestParam(required = false) String foodType,
            @RequestParam(required = false) String foodName,
            @RequestParam(required = false) String mealTime
    ) {
        return service.listByClientAndFilter(
                page, size, clientId, startDay, endDay, foodType, foodName, mealTime
        );
    }

    @PostMapping("/create")
    public ResponseBean<Void> create(@RequestBody MealRecord record) {
        return service.create(record);
    }

    @PutMapping("/update")
    public ResponseBean<Void> update(@RequestBody MealRecord record) {
        return service.update(record);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseBean<Void> delete(@PathVariable Integer id) {
        return service.deleteById(id);
    }
}
